import Vue from "vue"
let prototype = Vue.prototype;

export default {
    count: {
        service(id) {
            return new Promise((resolve, reject) => {
                prototype.$request({
                    api: "appraise.count.service",
                    data: {
                        id: id,
                    }
                }).then(response => {
                    if (response.code == 1) {
                        return resolve(response.data);
                    }
                    return reject(response.msg);
                }).catch(e => { });
            });
        },
        worker(id) {
            return new Promise((resolve, reject) => {
                prototype.$request({
                    api: "appraise.count.worker",
                    data: {
                        id: id,
                    }
                }).then(response => {
                    if (response.code == 1) {
                        return resolve(response.data);
                    }
                    return reject(response.msg);
                }).catch(e => { });
            });
        }
    },
    list: {
        /**
         * 服务评价
         */
        service(data) {
            return new Promise((resolve, reject) => {
                prototype.$request({
                    api: "appraise.list.service",
                    data: data
                }).then(response => {
                    if (response.code == 1) {
                        let list = [];
                        response.data.forEach((data) => {
                            list.push({
                                id: data.id,
                                avatar: data.u_avatar,
                                nickname: data.u_name,
                                createTime: data.time,
                                tags: data.msg ? data.msg.split(",") : [],
                                area: data.worker_city,
                                worker: data.worker_name,
                                grade: data.score,
                                images: data.img,
                                content: data.desc,
                            });
                        });
                        return resolve(list);
                    }
                    return reject(response.msg);
                }).catch(e => { });
            });
        },
        /**
         * 师傅评价
         */
        worker(data) {
            return new Promise((resolve, reject) => {
                prototype.$request({
                    api: "appraise.list.worker",
                    data: data
                }).then(response => {
                    if (response.code == 1) {
                        let list = [];
                        response.data.forEach((data) => {
                            list.push({
                                id: data.id,
                                avatar: data.u_avatar,
                                nickname: data.u_name,
                                createTime: data.time,
                                tags: data.msg ? data.msg.split(",") : [],
                                area: data.worker_city,
                                worker: data.worker_name,
                                grade: data.score,
                                images: data.img,
                                content: data.desc,
                            });
                        });
                        return resolve(list);
                    }
                    return reject(response.msg);
                }).catch(e => { });
            });
        }
    },
}
